package huawei.support.v4.widget;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.FontMetrics;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import androidx.viewpager.widget.ViewPager;
import androidx.viewpager.widget.ViewPager.OnPageChangeListener;
import java.util.Locale;
import o.fo;
import o.fpl.b;
import o.fpl.c;
import o.fpl.d;

public class HwDotsPageIndicator extends View implements OnPageChangeListener {
    private int ʻ;
    private float ʻॱ;
    private int ʼ;
    private Paint ʼॱ;
    private int ʽ;
    private float ʽॱ;
    private float ʾ;
    private Paint ʿ;
    private float ˈ;
    private String ˉ;
    private int ˊ;
    private boolean ˊˊ;
    private Runnable ˊˋ;
    private int ˊॱ;
    private boolean ˋ;
    private FontMetrics ˋˊ;
    private ViewPager ˋॱ;
    private boolean ˎ;
    private Handler ˏ;
    private float ˏॱ;
    private OnPageChangeListener ͺ;
    private int ॱ;
    private float ॱˊ;
    private int ॱˋ;
    private Paint ॱˎ;
    private int ॱॱ;
    private boolean ॱᐝ;
    private int ᐝ;
    private float[] ᐝॱ;

    public HwDotsPageIndicator(Context context) {
        this(context, null);
    }

    public HwDotsPageIndicator(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public HwDotsPageIndicator(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˊˊ = true;
        this.ˊˋ = new Runnable(this) {
            final /* synthetic */ HwDotsPageIndicator ॱ;

            {
                this.ॱ = r1;
            }

            public void run() {
                if (this.ॱ.ˋॱ == null || this.ॱ.ˋॱ.getAdapter() == null) {
                    Log.w("HwDotsPageIndicator", "Runnable, mViewPager=" + this.ॱ.ˋॱ);
                } else if (this.ॱ.ˋॱ.getAdapter().getCount() < 2) {
                    Log.w("HwDotsPageIndicator", "the page count is less than two");
                } else {
                    int ˋ = this.ॱ.ˋॱ.getCurrentItem();
                    if (ˋ == this.ॱ.ˋॱ.getAdapter().getCount() - 1) {
                        this.ॱ.ˋॱ.setCurrentItem(0, false);
                    } else {
                        this.ॱ.ˋॱ.setCurrentItem(ˋ + 1, true);
                    }
                    if (this.ॱ.ˎ) {
                        this.ॱ.ˏ.postDelayed(this.ॱ.ˊˋ, 5000);
                    }
                }
            }
        };
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, d.ᐝ, i, 0);
        this.ˎ = obtainStyledAttributes.getBoolean(d.ॱॱ, false);
        this.ʽ = obtainStyledAttributes.getColor(d.ʽ, fo.ˋ(getContext(), c.ˎ));
        this.ʻ = obtainStyledAttributes.getColor(d.ˏॱ, fo.ˋ(getContext(), c.ˋ));
        this.ˋ = obtainStyledAttributes.getBoolean(d.ॱˊ, true);
        obtainStyledAttributes.recycle();
        ˋ();
    }

    private void ˋ() {
        if (this.ˋ) {
            ॱ();
        } else {
            ˎ();
        }
        if (this.ˎ) {
            ʼ();
        }
        addOnAttachStateChangeListener(new OnAttachStateChangeListener(this) {
            final /* synthetic */ HwDotsPageIndicator ˏ;

            {
                this.ˏ = r1;
            }

            public void onViewAttachedToWindow(View view) {
                this.ˏ.ॱᐝ = true;
                if (this.ˏ.ˎ) {
                    this.ˏ.onPageScrolled();
                }
            }

            public void onViewDetachedFromWindow(View view) {
                this.ˏ.ॱᐝ = false;
                if (this.ˏ.ˎ) {
                    this.ˏ.ˊ();
                }
            }
        });
    }

    private void ˎ() {
        Resources resources = getResources();
        this.ॱ = resources.getDimensionPixelSize(b.ˏ);
        this.ˊ = resources.getDimensionPixelSize(b.ˏ);
        int dimensionPixelSize = resources.getDimensionPixelSize(b.ˎ);
        int ˋ = fo.ˋ(getContext(), c.ˏ);
        this.ʿ = new Paint(1);
        this.ʿ.setTextSize((float) dimensionPixelSize);
        this.ʿ.setColor(ˋ);
        this.ʿ.setTextAlign(Align.CENTER);
        this.ˋˊ = this.ʿ.getFontMetrics();
        this.ʾ = this.ˋˊ.bottom - this.ˋˊ.top;
    }

    private void ॱ() {
        Resources resources = getResources();
        this.ʼ = resources.getDimensionPixelSize(b.ॱ);
        this.ॱॱ = resources.getDimensionPixelSize(b.ˋ);
        this.ᐝ = resources.getDimensionPixelSize(b.ˊ);
        this.ॱ = resources.getDimensionPixelSize(b.ʻ);
        this.ˊ = resources.getDimensionPixelSize(b.ʻ);
        this.ˏॱ = ((float) this.ʼ) / 2.0f;
        this.ॱˎ = new Paint(1);
        this.ॱˎ.setColor(this.ʽ);
        this.ʼॱ = new Paint(1);
        this.ʼॱ.setColor(this.ʻ);
    }

    private void ʼ() {
        this.ˏ = new Handler();
    }

    public void setViewPager(ViewPager viewPager) {
        if (viewPager == null || viewPager.getAdapter() == null) {
            Log.w("HwDotsPageIndicator", "setViewPage, viewPager = " + viewPager);
            return;
        }
        this.ˋॱ = viewPager;
        ॱ(this.ˋॱ.getAdapter().getCount());
        viewPager.getAdapter().registerDataSetObserver(new DataSetObserver(this) {
            final /* synthetic */ HwDotsPageIndicator ˊ;

            {
                this.ˊ = r1;
            }

            public void onChanged() {
                this.ˊ.ॱ(this.ˊ.ˋॱ.getAdapter().getCount());
            }
        });
        viewPager.addOnPageChangeListener(this);
        ʻ();
    }

    public void onPageScrolled() {
        this.ˎ = true;
        if (this.ˏ == null) {
            ʼ();
        }
        this.ˏ.removeCallbacks(this.ˊˋ);
        this.ˏ.postDelayed(this.ˊˋ, 5000);
    }

    public void ˊ() {
        this.ˎ = false;
        if (this.ˏ != null) {
            this.ˏ.removeCallbacks(this.ˊˋ);
        }
        this.ˏ = null;
    }

    public void setOnPageChangeListener(OnPageChangeListener aVar) {
        this.ͺ = aVar;
    }

    public void onPageScrolled(int i, float f, int i2) {
        if (this.ͺ != null) {
            this.ͺ.onPageScrolled(i, f, i2);
        }
    }

    public void onPageScrollStateChanged(int i) {
        if (this.ॱᐝ) {
            setSelectedPage(i);
        } else {
            ʻ();
        }
        if (this.ͺ != null) {
            this.ͺ.onPageScrollStateChanged(i);
        }
    }

    public void onPageScrolled(int i) {
        if (this.ͺ != null) {
            this.ͺ.onPageScrolled(i);
        }
    }

    private void ॱ(int i) {
        this.ˊॱ = i;
        ʽ();
        requestLayout();
        invalidate();
    }

    private void ʽ() {
        if (this.ˋ) {
            ᐝ();
        } else {
            ॱॱ();
        }
    }

    private void ᐝ() {
        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        float width = (((float) this.ᐝ) / 2.0f) + ((((float) (((getWidth() - getPaddingRight()) - paddingLeft) - ˋॱ())) / 2.0f) + ((float) paddingLeft));
        this.ᐝॱ = new float[this.ˊॱ];
        for (paddingLeft = 0; paddingLeft < this.ˊॱ; paddingLeft++) {
            this.ᐝॱ[paddingLeft] = ((float) ((this.ʼ + this.ॱॱ) * paddingLeft)) + width;
        }
        this.ॱˊ = ((float) paddingTop) + (((float) ((this.ᐝ + this.ॱ) + this.ˊ)) / 2.0f);
        ʻ();
    }

    private void ॱॱ() {
        int paddingLeft = getPaddingLeft();
        float f = (float) paddingLeft;
        this.ʽॱ = (((float) ((getWidth() - getPaddingRight()) - paddingLeft)) / 2.0f) + f;
        this.ˈ = ((((float) getPaddingTop()) + (((this.ʾ + ((float) this.ॱ)) + ((float) this.ˊ)) / 2.0f)) + (this.ʾ / 2.0f)) - this.ˋˊ.bottom;
        ʻ();
    }

    private void ʻ() {
        this.ॱˋ = this.ˋॱ != null ? this.ˋॱ.getCurrentItem() : 0;
        if (this.ˋ) {
            if (this.ˊॱ > 0) {
                float f = (this.ˊˊ && ˏॱ()) ? this.ᐝॱ[(this.ˊॱ - 1) - this.ॱˋ] : this.ᐝॱ[this.ॱˋ];
                this.ʻॱ = f;
            }
        } else if (ˏॱ()) {
            this.ˉ = this.ˊॱ + "/" + (this.ॱˋ + 1);
        } else {
            this.ˉ = (this.ॱˋ + 1) + "/" + this.ˊॱ;
        }
    }

    protected void onMeasure(int i, int i2) {
        int ॱˊ = ॱˊ();
        switch (MeasureSpec.getMode(i2)) {
            case Integer.MIN_VALUE:
                if (ॱˊ > MeasureSpec.getSize(i2)) {
                    ॱˊ = MeasureSpec.getSize(i2);
                    break;
                }
                break;
            case 1073741824:
                ॱˊ = MeasureSpec.getSize(i2);
                break;
        }
        setMeasuredDimension(i, ॱˊ);
        ʽ();
    }

    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        setMeasuredDimension(i, i2);
        ʽ();
    }

    private int ॱˊ() {
        return (((this.ˋ ? this.ᐝ : (int) (this.ʾ + 0.5f)) + (this.ˊ + this.ॱ)) + getPaddingTop()) + getPaddingBottom();
    }

    private int ˋॱ() {
        return ((this.ˊॱ * this.ʼ) + (this.ᐝ - this.ʼ)) + ((this.ˊॱ - 1) * this.ॱॱ);
    }

    protected void onDraw(Canvas canvas) {
        if (this.ˊॱ > 0) {
            if (this.ˋ) {
                ˎ(canvas);
                onPageScrolled(canvas);
                return;
            }
            ˊ(canvas);
        }
    }

    private void ˊ(Canvas canvas) {
        if (canvas == null) {
            Log.w("HwDotsPageIndicator", "drawNumText, the canvas is null.");
        } else {
            canvas.drawText(this.ˉ, this.ʽॱ, this.ˈ, this.ʿ);
        }
    }

    private void ˎ(Canvas canvas) {
        if (canvas == null) {
            Log.w("HwDotsPageIndicator", "drawUnselected, the canvas is null.");
            return;
        }
        for (int i = 0; i < this.ˊॱ; i++) {
            canvas.drawCircle(this.ᐝॱ[i], this.ॱˊ, this.ˏॱ, this.ॱˎ);
        }
    }

    private void onPageScrolled(Canvas canvas) {
        if (canvas == null) {
            Log.w("HwDotsPageIndicator", "drawSelected, the canvas is null.");
        } else {
            canvas.drawCircle(this.ʻॱ, this.ॱˊ, ((float) this.ᐝ) / 2.0f, this.ʼॱ);
        }
    }

    public void setSelectedPage(int i) {
        if (i != this.ॱˋ && this.ˊॱ != 0) {
            this.ॱˋ = i;
            ʻ();
            invalidate();
        }
    }

    private boolean ˊॱ() {
        return getLayoutDirection() == 1;
    }

    private boolean ˏॱ() {
        boolean z;
        String language = Locale.getDefault().getLanguage();
        if (language.contains("ar") || language.contains("fa") || language.contains("iw")) {
            z = true;
        } else {
            z = false;
        }
        boolean z2;
        if (language.contains("ug") || language.contains("ur")) {
            z2 = true;
        } else {
            z2 = false;
        }
        if (z || r3 || ˊॱ()) {
            return true;
        }
        return false;
    }

    public void setRtlEnable(boolean z) {
        this.ˊˊ = z;
        invalidate();
    }
}
